package com.zjt.service;

import com.zjt.dao.IVersionUpdateDao;
import com.zjt.entity.VersionUpdate;
import com.zjt.web.api.vo.base.StateVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xueyanbeijing
 * Date: 12-8-29
 * Time: AM9:20
 * 版本管理接口实现类
 * To change this template use File | Settings | File Templates.
 */
@Component
public class VersionUpdateService implements IVersionUpdateService {
    private static Logger logger = LoggerFactory.getLogger(VersionUpdateService.class);
    private IVersionUpdateDao versionUpdateDao;
    @Autowired
    public void setVersionUpdateDao(IVersionUpdateDao versionUpdateDao) {
        this.versionUpdateDao = versionUpdateDao;
    }

    @Override
    public VersionUpdate checkVersionUpdate(String versionValue, String platform) {
        try
        {
            VersionUpdate versionUpdate = this.versionUpdateDao.findByVersionPlatformAndDeplyed(platform.trim().toLowerCase(),1);
            if (Long.parseLong(versionValue.trim().replace(".",""))>=Long.parseLong(versionUpdate.getVersionValue().trim()))//不需要更新
                return null;
            else return versionUpdate;
        }catch (Exception e){
           return null;
        }
    }

    @Override
    public List<VersionUpdate> getAllVersionUpdateList() {
        return this.versionUpdateDao.findAll();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<VersionUpdate> getVersionUpdateListByVersionPlatform(String versionPlatform) {
        return this.versionUpdateDao.findByVersionPlatform(versionPlatform);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public StateVO deplyVersion(String versionPlatform, String versionValue, String versionString) {
        StateVO stateVO = new StateVO();
        return stateVO;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public StateVO updateVersion(String versionPlatform, String versionValue, String versionString) {
        StateVO stateVO = new StateVO();
        return stateVO;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public VersionUpdate getVersionUpdateById(long Id) {
        return this.versionUpdateDao.findOne(Id);  //To change body of implemented methods use File | Settings | File Templates.
    }
}
